﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy3_5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            try
            {
                // 读取本次行驶公里数
                double currentDistance = double.Parse(txtDistance.Text);

                // 创建CountDistance对象，设置本次行驶里程并计算总里程
                CountDistance cd = new CountDistance();
                cd.Distance = currentDistance;
                cd.CalculateTotal();

                // 显示总行驶里程（通过“类名.静态属性”访问）
                MessageBox.Show($"您的汽车已行驶 {CountDistance.TotalDistance} 公里", "里程计算");

                // 清空输入框，准备下次输入
                txtDistance.Clear();
                txtDistance.Focus();
            }
            catch (FormatException)
            {
                MessageBox.Show("请输入有效的数字！", "格式错误");
            }
            catch (Exception ex)
            {
                MessageBox.Show("错误：" + ex.Message, "错误");
            }
        }
    }
}
